/** 
 * Project Name:eleme-website 
 * File Name:SpecDao.java 
 * Package Name:com.eleme.dao.impl 
 * Date:2018年1月3日下午2:48:12 
 * Copyright (c) 2018, fakedesigner@163.com All Rights Reserved. 
 * 
*/  
  
package com.eleme.dao.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.eleme.dao.ISpecDao;
import com.eleme.entity.Spec;
import com.eleme.entity.V_Goods_Spec;
import com.eleme.entity.V_Menu_Goods;

/** 
 * ClassName:SpecDao <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason:   TODO ADD REASON. <br/> 
 * Date:     2018年1月3日 下午2:48:12 <br/> 
 * @author   Pan 
 * @version   
 * @since    JDK 1.8 
 * @see       
 */
public class SpecDao extends BaseDao<Spec> implements ISpecDao {

	
	
	public Spec createEntity() {
		// TODO Auto-generated method stub
		return new Spec();
	}

	public List<V_Goods_Spec> getShopSpec(int shopid) {
		PreparedStatement ps = null;
		ResultSet rs = null;
		V_Goods_Spec res = null;
		List<V_Goods_Spec> li = new ArrayList<V_Goods_Spec>();
		String sql = "Select * From V_Goods_Spec Where shopid = ?";
		LOGGER.debug(sql);
		try {
			try {
				ps = getConnection().prepareStatement(sql);
				ps.setInt(1, shopid);
				rs = ps.executeQuery();
				if(rs != null) {
					while(rs.next()) {
						res = new V_Goods_Spec();
						res.setShopid(rs.getInt("shopid"));
						res.setGoodsid(rs.getInt("goodsid"));
						res.setSpecname(rs.getString("specname"));
						res.setSpecno(rs.getInt("specno"));
						res.setPrice(rs.getFloat("price"));
						li.add(res);
					}
				}
			} finally {
				rs.close();
				ps.close();
			}
			
			
		} catch (SQLException e) {
			LOGGER.error("获取菜单商品失败：" + e.getMessage());
			e.printStackTrace();
		}
		
		return li;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpecDao s = new SpecDao();
		List<V_Goods_Spec> g = s.getShopSpec(1);
		System.out.println(g.get(0).getSpecname());
	}

}
